<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'users-list.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/admin/js/static/h-ui/css/H-ui.min.css" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/admin/js/static/h-ui.admin/css/H-ui.admin.css" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/admin/js/lib/Hui-iconfont/1.0.8/iconfont.css" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/admin/js/static/h-ui.admin/skin/default/skin.css" id="skin" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/admin/js/static/h-ui.admin/css/style.css" />
  </head>
  
  <body>
	<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 用户中心 <span class="c-gray en">&gt;</span> 用户管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
	<div class="page-container">
		<div class="text-c"> <!--  日期范围：
			<input type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}' })" id="datemin" class="input-text Wdate" style="width:120px;">
			-
			<input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d' })" id="datemax" class="input-text Wdate" style="width:120px;">
			-->
			<!-- 
			<form action="${pageContext.request.contextPath}/agentManage/findAgent.do" method="post">
			 -->
				<input type="text" class="input-text" style="width:250px" placeholder="输入会员名称、电话、邮箱" id="key" name="" value="">
				<button type="submit" class="btn btn-success radius" id="search" name=""><i class="Hui-iconfont">&#xe665;</i> 搜中介</button>
			<!-- 
			</form>
			--> 
		</div>
		<div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"><a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> <a href="javascript:;" onclick="member_add('添加用户','${pageContext.request.contextPath}/admin/jsp/agent-add.jsp','','510')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加中介</a></span> <span class="r">共有数据：<strong><span id="total"></span></strong> 条</span> </div>
		<div class="mt-20">
		<table class="table table-border table-bordered table-hover table-bg table-sort">
			<thead>
				<tr class="text-c">
					<th width="25"><input type="checkbox" name="" value=""></th>
					<th width="20">ID</th>
					<th width="80">账号</th>
					<th width="40">姓名</th>
					<th width="50">性别</th>
					<th width="50">所属公司</th>
					<th width="130">身份证</th>
					<th width="50">联系方式</th>
					<th width="70">邮箱</th>
					<th width="130">审核状态</th>
					<th width="100">操作</th>
				</tr>
			</thead>
			<tbody>
				<!--  
				<c:forEach items="${agentList}" var="t">
					<tr class="text-c">
					<td><input type="checkbox" value="${t.agentId }" name="ids"></td>
					<td>${t.agentId }</td>
					<td><u style="cursor:pointer" class="text-primary" onclick="member_show('张三','member-show.html','10001','360','400')">${t.agentAccount }</u></td>
					<td>${t.agentName }</td>
					<td>${t.agentSex }</td>
					<td>${t.agentCompany }</td>
					<td>${t.agentIdentity }</td>
					<td class="text-l">${t.agentTele }</td>
					<td class="td-status"><span class="label label-success radius">${t.agentEmail }</span></td>
					<td>${t.applyState }</td>
					<td class="td-manage"><a title="编辑" href="javascript:;" onclick="user_edit('编辑','${pageContext.request.contextPath}/admin/jsp/agent-edit.jsp','${t.agentId}','','510')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a> <a style="text-decoration:none" class="ml-5" onClick="change_password('修改密码','change-password.html','10001','600','270')" href="javascript:;" title="修改密码"><i class="Hui-iconfont">&#xe63f;</i></a> <a title="删除" href="javascript:;" onclick="member_del(this,${t.agentId })" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
				</tr>
                </c:forEach>
				-->
			</tbody>
		</table>
		</div>
	</div>
	<!--_footer 作为公共模版分离出去-->
	<script type="text/javascript" src="${pageContext.request.contextPath}/admin/js/lib/jquery/1.9.1/jquery.min.js"></script> 
	<script type="text/javascript" src="${pageContext.request.contextPath}/admin/js/lib/layer/2.4/layer.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/admin/js/static/h-ui/js/H-ui.min.js"></script> 
	<script type="text/javascript" src="${pageContext.request.contextPath}/admin/js/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->
	
	<!--请在下方写此页面业务相关的脚本-->
	<script type="text/javascript" src="${pageContext.request.contextPath}/admin/js/lib/My97DatePicker/4.8/WdatePicker.js"></script> 
	<script type="text/javascript" src="${pageContext.request.contextPath}/admin/js/lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
	<script type="text/javascript" src="${pageContext.request.contextPath}/admin/js/lib/laypage/1.2/laypage.js"></script>
	<script type="text/javascript">
	$(function(){
		 var CONSTANT = {
		        DATA_TABLES : {
		            DEFAULT_OPTION : { //DataTables初始化选项
		                language: {
		                    "sProcessing":   "处理中...",
		                    "sLengthMenu":   "每页 _MENU_ 项",
		                    "sZeroRecords":  "没有匹配结果",
		                    "sInfo":         "当前显示第 _START_ 至 _END_ 项，共 _TOTAL_ 项。",
		                    "sInfoEmpty":    "当前显示第 0 至 0 项，共 0 项",
		                    "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
		                    "sInfoPostFix":  "",
		                    "sSearch":       "搜索:",
		                    "sUrl":          "",
		                    "sEmptyTable":     "表中数据为空",
		                    "sLoadingRecords": "载入中...",
		                    "sInfoThousands":  ",",
		                    "oPaginate": {
		                        "sFirst":    "首页",
		                        "sPrevious": "上页",
		                        "sNext":     "下页",
		                        "sLast":     "末页",
		                        "sJump":     "跳转"
		                    },
		                    "oAria": {
		                        "sSortAscending":  ": 以升序排列此列",
		                        "sSortDescending": ": 以降序排列此列"
		                    }
		                },
		                autoWidth: false,   //禁用自动调整列宽
		                stripeClasses: ["odd", "even"],//为奇偶行加上样式，兼容不支持CSS伪类的场合
		                order: [],          //取消默认排序查询,否则复选框一列会出现小箭头
		                processing: false,  //隐藏加载提示,自行处理
		                serverSide: true,   //启用服务器端分页
		                searching: false    //禁用原生搜索
		            },
		            COLUMN: {
		                CHECKBOX: { //复选框单元格
		                    className:"td-checkbox",
		                    orderable: false,
		                    width: "30px",
		                    data: null,
		                    render: function (data, type, row, meta) {
		                        return '<input type="checkbox" class="iCheck">';
		                    }
		                }
		            }
		        }
		};
		var _table= $('.table-sort').dataTable({
			language:CONSTANT.DATA_TABLES.DEFAULT_OPTION.language,  //提示信息
            autoWidth: true,  //禁用自动调整列宽
            stripeClasses: ["odd", "even"],  //为奇偶行加上样式，兼容不支持CSS伪类的场合
            processing: true,  //隐藏加载提示,自行处理
            serverSide: true,  //启用服务器端分页
            searching: false,  //禁用原生搜索
            orderMulti: false,  //启用多列排序
            order: [],  //取消默认排序查询,否则复选框一列会出现小箭头
            renderer: "jquery-ui",  //渲染样式：Bootstrap和jquery-ui
            pagingType: "simple_numbers",  //分页样式：simple,simple_numbers,full,full_numbers
            columnDefs: [{
                "targets": 'nosort',  //列的样式名
                "orderable": false    //包含上样式名‘nosort’的禁止排序
            }],
            ajax: function (data, callback, settings) {
                //封装请求参数
                var param = getParam(data);
               // var param = {};
              //  param.curr = (data.start / data.length)+1;;
            //    param.pageSize = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
                /*
                param.start = data.start;//开始的记录序号
                param.page = (data.start / data.length)+1;//当前页码
                */
                //console.log(param);
                //ajax请求数据
                $.ajax({
                    type: "GET",
                    url: "${pageContext.request.contextPath}/agentManage/getPageData.do",
                    cache: false,  //禁用缓存
                    data: param,  //传入组装的参数
                    dataType: "json",
                    success: function (result) {
                        //setTimeout仅为测试延迟效果
                    //    setTimeout(function () {
                            //封装返回数据
                         	document.getElementById("total").innerText=result.total;
                            var returnData = {};
                            returnData.draw = data.draw;//这里直接自行返回了draw计数器,应该由后台返回
                            returnData.recordsTotal = result.total;//返回数据全部记录
                            returnData.recordsFiltered = result.total;//后台不实现过滤功能，每次查询均视作全部结果
                            returnData.data = result.data;//返回的数据列表 
                            //console.log(returnData);
                            //调用DataTables提供的callback方法，代表数据已封装完成并传回DataTables进行渲染
                            //此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕
                            callback(returnData);
                    //   }, 200);
                    }
                });
            },
            //列表表头字段
            aoColumns: [
            	CONSTANT.DATA_TABLES.COLUMN.CHECKBOX,
                { "data": "agentId" },
                { "data": "agentAccount" },
                { "data": "agentName"},
                { "data": "agentSex"},
                { "data": "agentCompany" },
                { "data": "agentIdentity"},
                { "data": "agentTele"},
                { "data": "agentEmail"},
                { "data": "applyState"},
                { 
                	"data": null,
                	"defaultContent":""
                }
            ],
            "createdRow": function ( row, data, index ) {
            //行渲染回调,在这里可以对该行dom元素进行任何操作
            //给当前行加样式
          //  <a title="删除" href="javascript:;" onclick="member_del(this,${t.userId })" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
            //不使用render，改用jquery文档操作呈现单元格
            var $btnEdit = $('<button type="button" class="btn btn-small btn-primary btn-edit" onclick="user_edit(this)" >修改</button>');
            var $btnDel = $('<button type="button" class="btn btn-small btn-danger btn-del" onclick="user_dele(this)">删除</button>');
            $('td', row).eq(10).append($btnEdit).append($btnDel);
 
        }
        }).api();
        $("#search").click(function(){
			_table.draw();
		});
	});
	
	function getParam(data)
	{
		var param = {};
		var key = document.getElementById("key").value;
		param.curr = (data.start / data.length)+1;;
        param.pageSize = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
		if(key.trim().length != 0)
		{
			param.key= key;
		}
		else
		{
			param.key = "";
		}
		return param;
		
	}
	function user_dele(curr)
	{
		var tr = curr.parentNode.parentNode;
		var id = tr.cells[1].innerHTML;
		member_del(curr, id);
		alert(id);
	}
	
	/*用户-添加*/
	function member_add(title,url,w,h){
		layer_show(title,url,w,h);
		$('.btn-refresh').click();
	}
	/*用户-查看*/
	function member_show(title,url,id,w,h){
		layer_show(title,url,w,h);
	}
	
	/*用户-编辑*/
	function user_edit(curr){
		var tr = curr.parentNode.parentNode;
		var id = tr.cells[1].innerHTML;
		$.ajax({
				type: 'POST',
				url: '${pageContext.request.contextPath}/agentManage/getAgentById.do',
				dataType: 'text',
				contentType :"application/x-www-form-urlencoded",
				data:{agentId:id},
				success: function(data){
					layer_show('编辑','${pageContext.request.contextPath}/admin/jsp/agent-edit.jsp','','510');
				},
				error:function(data) {
					console.log(data.msg);
				},
			});		
		
	}
	/*密码-修改*/
	function change_password(title,url,id,w,h){
		layer_show(title,url,w,h);	
	}
	/*批量删除*/
	function datadel(){
		 var ii=0;
		 var agentIds = "";
         var cks=document.getElementsByClassName("iCheck");
         for(var i =0;i<cks.length;i++){
             if(cks[i].checked){
               var tr = cks[i].parentNode.parentNode;
		 	   var id = tr.cells[1].innerHTML;
               agentIds += id+'#';
               ii++;
             }
         }
         if(ii==0){
	         alert("至少选择一条");
	         return;
         }
         else{
			alert(agentIds);
         	layer.confirm('确认要删除吗？',function(index){
	        	$.ajax({
					type: 'POST',
					url: '${pageContext.request.contextPath}/agentManage/batchdeleteAgent.do',
					dataType: 'text',
					contentType :"application/x-www-form-urlencoded",
					data:{agentIds:agentIds},
					success: function(data){
						//$(obj).parents("tr").remove();
					    parent.$('.btn-refresh').click();
						layer.msg('已删除!',{icon:1,time:1000});
					},
					error:function(data) {
						console.log(data.msg);
					},
				});
			});		
        } 
        
	}
	/*用户-删除*/
	function member_del(obj,id){
		layer.confirm('确认要删除吗？',function(index){
			$.ajax({
				type: 'POST',
				url: '${pageContext.request.contextPath}/agentManage/deleteAgent.do',
				dataType: 'text',
				contentType :"application/x-www-form-urlencoded",
				data:{agentId:id},
				success: function(data){
					$(obj).parents("tr").remove();
					parent.$('.btn-refresh').click();
					layer.msg('已删除!',{icon:1,time:1000});
				},
				error:function(data) {
					console.log(data.msg);
				},
			});		
		});
	}
	
	function search()
	{
		var key = document.getElementById("key").value;
		alert(key);
		$.ajax({
				type: 'POST',
				url: '${pageContext.request.contextPath}/agentManage/findAgent.do',
				dataType: 'text',
				contentType :"application/x-www-form-urlencoded",
				data:{key:key},
				success: function(data){
					$(obj).parents("tr").remove();
					parent.$('.btn-refresh').click();
					layer.msg('已删除!',{icon:1,time:1000});
				},
				error:function(data) {
					console.log(data.msg);
				},
			});		
		
	}
	</script> 
	</body>
</html>
